package com.yunbiao.ybbusstopplate.utils.core;

import android.util.Log;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.yunbiao.ybbusstopplate.base.APP;
import com.yunbiao.ybbusstopplate.message.OnCityLocationSuccessEvent;
import com.yunbiao.ybbusstopplate.utils.SpTool;
import com.yunbiao.ybbusstopplate.utils.SpUtils;


import org.greenrobot.eventbus.EventBus;

/**
 * 定位获得的数据
 */
class MyLocationListener implements BDLocationListener {
    private static final String TAG = "MyLocationListener";
    @Override
    public void onReceiveLocation(BDLocation location) {
        if (null != location && location.getLocType() != BDLocation.TypeServerError) {
            LocationBean locationBean = new LocationBean();
            locationBean.setCity(location.getCity() + "");
            locationBean.setAltitude(String.valueOf(location.getLatitude()));
            locationBean.setLongitude(String.valueOf(location.getLongitude()));
            locationBean.setAdressHeight(location.getAltitude() + "");
            locationBean.setAdress(location.getAddrStr());
            MachineDetial.getInstance().setLocation(locationBean);
            MachineDetial.getInstance().getLocation();

            SpUtils.saveString(APP.Companion.getAppContext(), SpUtils.CITY_NAME,location.getCity());
            String city = SpUtils.getString(APP.Companion.getAppContext(),SpUtils.CITY_NAME,"");
            EventBus.getDefault().post(new OnCityLocationSuccessEvent(city));
            Log.e(TAG, "city----------》"+city );
        }
    }


}
